#ifndef STOCKINSTATISTICS_H
#define STOCKINSTATISTICS_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QComboBox>
#include <QDateEdit>
#include <QTableWidget>
#include <QLabel>
#include <QFrame>
#include <QHeaderView>
#include <QScrollArea>
#include <QGroupBox>

class InventoryService;

class StockInStatistics : public QWidget
{
    Q_OBJECT

public:
    explicit StockInStatistics(const QMap<QString, QVariant> &userInfo, QWidget *parent = nullptr);
    ~StockInStatistics();

private slots:
    void onReturnClicked();
    void onRefreshClicked();
    void onSearchClicked();
    void onResetClicked();
    void onExportClicked();
    void onProductChanged(int index);

private:
    void initUI();
    void setupStyles();
    void setupTable();
    void loadData();
    void loadProducts();
    void filterData();
    void updateTable();
    void updateStatistics();
    void clearFilters();

    // 布局控件
    QVBoxLayout *m_mainLayout;
    QHBoxLayout *m_topButtonLayout;
    QVBoxLayout *m_contentLayout;
    QHBoxLayout *m_filterLayout;
    QHBoxLayout *m_statisticsLayout;
    QVBoxLayout *m_tableLayout;
    QFrame *m_shadowContainer;
    QScrollArea *m_scrollArea;
    QWidget *m_contentWidget;

    // 顶部按钮
    QPushButton *m_btnReturn;
    QPushButton *m_btnRefresh;
    QPushButton *m_btnExport;

    // 筛选控件
    QGroupBox *m_filterGroup;
    QGridLayout *m_filterGridLayout;
    QLabel *m_lblStartDate;
    QLabel *m_lblEndDate;
    QLabel *m_lblProduct;
    QLabel *m_lblSupplier;
    QDateEdit *m_dateStart;
    QDateEdit *m_dateEnd;
    QComboBox *m_cmbProduct;
    QLineEdit *m_edtSupplier;
    QPushButton *m_btnSearch;
    QPushButton *m_btnReset;

    // 统计信息标签（紧凑型，位于顶部）
    QLabel *m_lblTotalRecords;
    QLabel *m_lblTotalQuantity;
    QLabel *m_lblTotalAmount;
    QLabel *m_lblAveragePrice;

    // 数据表格
    QTableWidget *m_tableWidget;

    // 数据存储
    QVector<QMap<QString, QVariant>> m_allRecords;
    QVector<QMap<QString, QVariant>> m_filteredRecords;
    QMap<QString, QVariant> m_currentUser;

    // 服务层对象
    InventoryService *m_inventoryService;
};

#endif // STOCKINSTATISTICS_H